<!DOCTYPE html>
<html>
<head>
    <title>{$platform.name}</title>
    <link href="/static/css/framework-font.css" rel="stylesheet"/>
    <script src="/static/js/jquery-2.1.1.js"></script>
    <script src="/static/bootstrap/js/bootstrap.js"></script>
    <link href="/static/bootstrap/css/bootstrap.min.css" rel="stylesheet"/>

    <script src="/static/js/jquery.cookie.js"></script>
    <link href="/static/css/framework-theme.css" rel="stylesheet"/>
    <!--    <script src="/static/js/framework-ui.js"></script>-->
    <!--    <script src="/static/js/framework-clientdata.js"></script>-->

    <!--弹框js-->
    <script src="/static/js/yii.js"></script>

    <!--引用layui弹框插件-->
    <script src="/static/layui/layui.all.js"></script>
    <script src="/static/layui/layui.js"></script>
    <link href="/static/layui/css/layui.css" rel="stylesheet"/>
    <script src="/static/layui/lay/modules/layer.js"></script>


    <!--    配置select多选相关-->
    <!--    <script src="/static/layui/dist/xm-select.js"></script>-->


        {if condition="$swidthStyle eq 0"}
    <link href="/static/css/pattern/public.css" rel="stylesheet"/>
    {else/}
    <link href="/static/css/default/public.css" rel="stylesheet"/>
    {/if}

    <script src="/static/build/tracking-min.js"></script>
    <script src="/static/build/data/face-min.js"></script>
    <script src="/static/build/data/eye-min.js"></script>
    <script src="/static/build/data/mouth-min.js"></script>
</head>
<body>
<style>
    html, body {
        background-color: #FFF !important;
    }

    .modal-body {
        background-color: #fff;
        padding: 15px
    }

    .page-header {
        margin-top: 15px !important;
    }

    .geographic input {
        width: 100px !important;
        float: left;
        margin-right: 15px;
    }

    .new-content {
        padding: 15px 0px
    }

    .config_img {
        max-width: 75px;
        max-height:75px;
        margin-top: 15px;
    }
    .images_del{text-align: center}
</style>

<div class="modal-body">


    <div class="modal-header">

        <div class="assistant_header">
            <button type="button" class="close" data-dismiss="modal" close="true">
                <span aria-hidden="true">×</span>
            </button>
            <h4 class="modal-title">
                <span class="fa fa-legal"></span>修改内容
            </h4>
        </div>
    </div>

    <div class="new-content">
        <form class="form-horizontal layui-form">


            <div class="form-group">
                <label class="col-sm-1 control-label">*所属导航:</label>
                <div class="col-sm-3">
                    <select name="nav_id" lay-verify="nav_id" lay-filter="nav_id" class="select"  lay-search="">
                    {volist name="nav" id="vo"}
                        <option value="{$vo.id}" {if condition="$detail['nav_id'] eq $vo['id']"} selected {/if} >{$vo.name}</option>
                    {/volist}
                    </select>
                </div>

                <label class="col-sm-1 control-label">*所属栏目:</label>
                <div class="col-sm-3">
                    <select name="classify_id" lay-verify="classify_id" lay-filter="classify_id" class="select"  lay-search="">
                        {volist name="classify" id="vo"}
                        <option value="{$vo.id}" {if condition="$detail['classify_id'] eq $vo['id']"} selected {/if}>{$vo.name}</option>
                        {volist name="$vo['child']" id="vo1"}
                        <option value="{$vo1.id}" {if condition="$detail['classify_id'] eq $vo1['id']"} selected {/if}>--{$vo1.name}</option>
                        {/volist}
                        {/volist}
                    </select>
                </div>

            </div>


            <div class="form-group">
                <label class="col-sm-1 control-label">标题:</label>
                <div class="col-sm-3">
                    <input type="text" class="form-control" name="title" placeholder="标题" value="{$detail['title']}">
                </div>
            </div>

            <div class="form-group address">
                <label class="col-sm-1 control-label newtitle">所在地址:</label>
                <div class="col-sm-3">
                    <input type="text" class="form-control" name="address" placeholder="所在地址" value="{$detail['address']}">
                </div>
            </div>

            <div class="form-group hot">
                <label class="col-sm-1 control-label newtitle">推荐设置:</label>
                <div class="col-sm-3">
                    <select name="hot">
                        <option value="0" {if condition="$detail['hot'] eq 0"} selected {/if}>普通</option>
                        <option value="1" {if condition="$detail['hot'] eq 1"} selected {/if}>首页推荐</option>
                    </select>
                </div>
            </div>


            <div class="form-group">
                <label class="col-sm-1 control-label">缩略图:</label>
                <div class="col-sm-4">
                    <div class="input-group ">
                        <input type="text" id="thumb" name="thumb" value="{$detail['thumb']}" class="form-control" autocomplete="off">
                        <span class="input-group-btn">
                        <button class="btn btn-default" id="upload" type="button" data-original-title="" title="">选择图片</button>
                    </span>
                    </div>
                    <img class="config_img thumb" src="{$detail['thumb']}" >
                </div>
            </div>

            <div class="form-group group_photo images">
                <label class="col-sm-1 control-label">图片组:</label>
                <!--存储上传的图片信息-->
                <div class="col-sm-4">
                    <div class="input-group ">
                        <input type="text" id="images" disabled name="images" value="" class="form-control" autocomplete="off">
                        <span class="input-group-btn">
                        <button class="btn btn-default" id="images_upload" type="button" data-original-title="" title="">选择图片</button>
                    </span>
                    </div>
                </div>
            </div>

            <div class="form-group group_photo images">
                <label class="col-sm-1 control-label"></label>
                <!--存储上传的图片信息-->
                <div class="col-sm-8">
                    <div class="input-group show_multiple row">
                        {volist name="$images" id="vo1"}
                        <div class="newimg"><img src="{$vo1}" ><input type="hidden" name="images[]" value="{$vo1}"><div class="images_del" >删除</div></div>
                        {/volist}
                    </div>
                </div>
            </div>



            <div class="form-group js_photos" {if condition="$type neq 1 && $type neq 6 && $type neq 4 && $type neq 9"} style="display: none" {/if}>
                    <label class="col-sm-1 control-label"> 视频文件</label>
                    <div class="col-sm-3">
                        <input type="radio" name="videoType" lay-filter="videoType" value="1" title="本地上传" checked="">
                        <input type="radio" name="videoType" lay-filter="videoType" value="2" title="外部链接">
                    </div>
            </div>

            <div class="form-group js_photos" {if condition="$type neq 1 && $type neq 6 && $type neq 4 && $type neq 9"} style="display: none" {/if} >
                <label class="col-sm-1 control-label"> </label>
                <div class="col-sm-3">

                    <div class="input-group type_2">
                        <input type="file" name="" class="do_upload" data-val="path"  style="display: none">
                        <input type="text" class="form-control path" disabled value="{$detail.path}" >
                        <span class="group-span-filestyle input-group-btn" tabindex="0">
                            <label class="btn btn-default id_photos" data-original-title="" title="">
                                <span class="glyphicon glyphicon-folder-open"></span>上传
                            </label>
                        </span>
                    </div>

                    <div class="input-group type_1" style="display: none">
                        <input type="text" class="form-control path" name="path"  value="{$detail.path}" >
                    </div>

                </div>
            </div>


            <div  class="form-group" >
                <label class="col-sm-1 control-label">简介:</label>
                <div class="col-sm-8">
                    <textarea name="desc" class="layui-textarea">{$detail.desc}</textarea>
                </div>
            </div>

            <!--图文模型&单页模型-->
            <div class="form-group" {if condition="$type neq 1 && $type neq 6 && $type neq 4 && $type neq 9"} style="display: none" {/if} >
                <label class="col-sm-1 control-label">内容:</label>
                <div class="col-sm-8">
                    <textarea id="content" >{$detail.content}</textarea>
                </div>
            </div>

            <!--外部链接-->
            <div class="form-group" {if condition="$type neq 3"} style="display: none" {/if}>
                <label class="col-sm-1 control-label">链接地址:</label>
                <div class="col-sm-8">
                    <input type="text" class="form-control" name="link" placeholder="链接地址" value="{$detail.link}">
                </div>
            </div>

            <!--号码簿-->
            <div class="form-group" {if condition="$type neq 5"} style="display: none" {/if}>
            <label class="col-sm-1 control-label">电话号码:</label>
            <div class="col-sm-8">
                <input type="text" class="form-control" name="mobile" placeholder="电话号码" value="{$detail.mobile}">
            </div>
            </div>


            <!--活动-->
            <div class="form-group interval" {if condition="$type neq 4"} style="display: none" {/if}>
            <label class="col-sm-1 control-label">开始时间:</label>
            <div class="col-sm-2">
                <input type="text" class="form-control test-item"  name="start_time" placeholder="开始时间" value="{$detail.start_time|date='Y-m-d H:i:s',###}">
            </div>

            <label class="col-sm-1 control-label">结束时间:</label>
            <div class="col-sm-2">
                <input type="text" class="form-control test-item" name="end_time" placeholder="结束时间" value="{$detail.end_time|date='Y-m-d H:i:s',###}">
            </div>

            <label class="col-sm-1 control-label">积分:</label>
            <div class="col-sm-2">
                <input type="number" class="form-control" name="integral" placeholder="积分" value="{$detail.integral}">
            </div>

            </div>

            <div class="form-group">
                <label class="col-sm-1 control-label">发布日期:</label>
                <div class="col-sm-2">
                    <input type="text" class="form-control" id="test" name="Wdate" placeholder="发布日期" value="{$detail.Wdate}">
                </div>

                <label class="col-sm-1 control-label">作者:</label>
                <div class="col-sm-2">
                    <input type="text" class="form-control" name="author" placeholder="作者" value="{$detail.author}">
                </div>

                <label class="col-sm-1 control-label">来源:</label>
                <div class="col-sm-2">
                    <input type="text" class="form-control" name="source" placeholder="来源" value="{$detail.source}">
                </div>
            </div>


            <div class="form-group">
                <label class="col-sm-1 control-label">排序:</label>
                <div class="col-sm-2">
                    <input type="text" class="form-control" name="sort" placeholder="排序" value="{$detail.sort}">
                </div>

                <label class="col-sm-1 control-label">状态:</label>
                <div class="col-sm-2">
                    <select name="status">
                        <option value="1" {if condition="$detail['status'] eq 1"} selected {/if}>启用</option>
                        <option value="2" {if condition="$detail['status'] eq 2"} selected {/if}>禁用</option>
                    </select>
                </div>
            </div>

            <input type="hidden" name="id"value="{$detail.id}">

        </form>

    </div>
    <div class="assistant_button">
        <a type="button" class="layui-btn layui-btn-primary js_quit" href="{:URL('community/Content/index')}?colony_id={$colony_id}&classify_id={$classify_id}" >取消</a>
        <!--        <button type="button" class="btn btn-primary btn-sm js_add" _event="add" data-id="0" data-name="">保存</button>-->
        <a type="button" class="layui-btn js_add" id="newsave">保存</a>
    </div>

</div>


<script>
    $(".show_multiple").on("click",".images_del",function () {
        $(this).parent().remove();
    })
    var newModal = new yii.modal();
    //文件页面
    $("#upload").click(function () {
        $(newModal.getid()).show();
        newModal.initialization({
            url: "{:URL('common/upload/index')}",
            type: "post",
            data:{
                type:'detail'
            }
        });
    });

    newModal.on("upload",function(data){
        var images = '';
        $(newModal.getid()).find("#data-area .newimages .active img").each(function () {
            images = $(this).attr('src');
            return false
        })
        $(newModal.getid()).hide();
        //$(".modal-backdrop").remove();
        //$('#nowMainProjectDataForm').modal('hide');
        $(newModal.getid()).find(".modal").hide();
        $("#thumb").val(images);
        $(".config_img").attr("src",images)
    });

    //多图片上传
    $("#images_upload").click(function () {
        $(newModal.getid()).show();
        newModal.initialization({
            url: "{:URL('common/upload/index')}",
            type: "post",
            data:{
                type:'detail',
                multiple:'multiple'
            }
        });
    });

    newModal.on("multiple",function(data){
        var images = '';
        $(newModal.getid()).find("#data-area .newimages .active img").each(function () {
            images += '<div class="newimg"><img src="'+$(this).attr('src')+'" ><input type="hidden" name="images[]" value="'+$(this).attr('src')+'"><div class="images_del" >删除</div></div>';
        })
        $(newModal.getid()).hide();
        //遮罩层隐藏
        //$('#nowMainProjectDataForm').modal('hide');
        $(".modal-backdrop").remove();
        $(newModal.getid()).find(".modal").hide();
        $(".show_multiple").append(images);
    });

    $(".id_photos").click(function () {
        $(this).parent().parent().find(".do_upload").click();
    });

    $('.js_photos').on('change','.do_upload',function(){
        var content = $(this).attr("data-val");
        var formData = new FormData();
        var name = $($(this)).val();
        var files = $($(this))[0].files[0];
        formData.append("file", files);
        formData.append("name", name);
        //另外加的参数
        formData.append("act", "PostImg");
        // var index = layer.msg('正在提交中....');

        $.ajax({
            url: "{:URL('common/upload/textUpload')}",
            type: 'POST',
            data: formData,
            processData: false,
            contentType: false,
            dataType: 'json',
            success:function (res) {
                if(res.code!=0){
                    layer.alert(res.msg);
                }else{
                    $("."+content).val(res.path);
                    $("."+content).attr("src",res.path);
                }
            }
            ,error:function (res) {
                alert('错误');
            }
        });
    })

    layui.extend({
        tinymce: '{/}/static/tinymce/tinymce'
    }).use(['tinymce','form', 'jquery', 'layer', 'laydate','layedit'], function () {
        var tinymce = layui.tinymce;
        tinymce.render({
            elem:'#content',
            height: 600,
            images_upload_handler: function (blobInfo, succFun, failFun) {
                var xhr, formData;
                var file = blobInfo.blob();//转化为易于理解的file对象
                xhr = new XMLHttpRequest();
                xhr.withCredentials = false;
                xhr.open('POST', "{:URL('/common/upload/textUpload')}");
                xhr.onload = function() {
                    var json;
                    json = JSON.parse(xhr.responseText);
                    succFun(json.path);
                };
                formData = new FormData();
                formData.append('file', file, file.name );//此处与源文档不一样
                xhr.send(formData);
            }
        });

        var $ = layui.jquery, layer = layui.layer;
        var form = layui.form;
        var laydate = layui.laydate;
        var layedit = layui.layedit;


        //同时绑定多个
        lay('.test-item').each(function(){
            laydate.render({
                elem: this
                ,trigger: 'click'
                ,type: 'datetime'
            });
        });

        laydate.render({
            elem: '#test'
            //,type: 'date' //默认，可不填
        });



        form.on('radio(videoType)', function (data) {
            var value = data.value;
            if(value == 1){
                $(".type_2").show();
                $(".type_1").hide();
            }else{
                $(".type_1").show();
                $(".type_2").hide();
            }
        });

        //选中栏目
        form.on('select(classify_id)', function (data) {
            //获取栏目模型
            var id = data.value;
            $.ajax({
                type: 'post',
                url: "{:URL('community/Content/findType')}",
                data: {id: id},
                dataType: 'JSON',
                success: function (res) {
                    var type = res.data;

                    //文章模型
                    if(type==1){
                        $('input[name="videoType"]').parent().parent().show();
                        $('input[name="path"]').parent().parent().parent().show();
                        $('input[name="link"]').parent().parent().hide();
                        $('#content').parent().parent().show();

                        $('.address').show();
                        $('.hot').show();
                        $(".images").show();
                        $('input[name="mobile"]').parent().parent().hide();
                    }else if(type==3){
                        $('input[name="videoType"]').parent().parent().hide();
                        $('input[name="path"]').parent().parent().parent().hide();
                        $('input[name="link"]').parent().parent().show();
                        $('#content').parent().parent().hide();
                        $('input[name="mobile"]').parent().parent().hide();
                    }else if(type==5){
                        $('input[name="videoType"]').parent().parent().hide();
                        $('input[name="path"]').parent().parent().parent().hide();
                        $('input[name="link"]').parent().parent().hide();
                        $('#content').parent().parent().hide();
                        $('input[name="mobile"]').parent().parent().show();
                    }else if(type==7){
                        $('.address').hide();
                        $('.hot').hide();
                        $(".images").hide();
                    }else{
                        $('#content').parent().parent().show();
                    }

                },
                error: function (res) {
                }
            });
        });

        //获取栏目
        form.on('select(nav_id)', function (data) {
            //触发联动
            var id = data.value;
            $.ajax({
                type: 'post',
                url: "{:URL('community/Content/findClassify')}",
                data: {nav_id: id},
                dataType: 'JSON',
                success: function (res) {
                    var data = res.data;
                    //生成楼栋信息
                    var html = '<option value="">请选择栏目</option>';
                    $.each(data, function(e,v){
                        html +='<option value="'+v.id+'" data-type="'+v.type+'">'+v.name+'</option>';
                        $.each(v.child, function(e1,v1){
                            html +='<option value="'+v1.id+'" data-type="'+v.type+'">--'+v1.name+'</option>';
                        });
                    });
                    $('select[name="classify_id"]').html(html);
                    form.render('select');
                },
                error: function (res) {
                }
            });
        });

        $("#newsave").click(function () {
            var content = tinymce.get('#content').getContent();
            var data = $("form").serializeArray();
            data.push({name: "content", value: content});
            $.ajax({
                type: 'post',
                url: "{:URL('community/Article/doLists')}",
                data: data,
                dataType: 'JSON',
                success: function (res) {
                    if (res.code != 0) {
                        layer.alert(res.msg);
                    } else {
                        window.location.href = "{:URL('community/content/index')}?classify_id="+res.classify_id;
                    }
                },
                error: function (res) {

                }
            });
        })


        form.render('select');


    })


</script>

</body>
</html>